import type { ConsumptionForm, CreateOrUpdateForm, SelectForm } from '#/member-management'
import request from '@/utils/request'
import dayjs from 'dayjs'

// 获取会员列表
export function getMemberList(selectForm: SelectForm) {
  return request({
    url: '/vip/vipPage',
    method: 'post',
    data: selectForm
  })
}

// 新增编辑会员
export function addOrUpdateMemberItem(createForm: CreateOrUpdateForm) {
  return request({
    url: '/vip/saveVipInfo',
    method: 'post',
    data: {
      ...createForm,
      rechargeDate: dayjs(createForm.rechargeDate).format('YYYY-MM-DD')
    }
  })
}

// 删除会员
export function deleteMemberById(id: number) {
  return request({
    url: '/vip/deleteVip',
    method: 'delete',
    params: {
      id
    }
  })
}

// 新增编辑消费记录
export function addOrUpdateMemberConsumption(consumptionForm: ConsumptionForm) {
  return request({
    url: '/vip/saveConsume',
    method: 'post',
    data: {
      ...consumptionForm,
      consumeTime: dayjs(consumptionForm.consumeTime).format('YYYY-MM-DD HH:mm:ss')
    }
  })
}

// 获取消费记录
export function getMemberConsumptionById(vipId: number) {
  return request({
    url: '/vip/consumeLogs',
    method: 'get',
    params: {
      vipId
    }
  })
}

// 删除消费记录
export function deleteConsumptionById(id: number) {
  return request({
    url: '/vip/deleteConsume',
    method: 'delete',
    params: {
      id
    }
  })
}
